package com.aube.mis.controller;

import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.aube.mis.dto.DanmuDTO;
import com.aube.mis.dto.LotteryDTO;
import com.aube.mis.dto.LotteryOptionDTO;
import com.aube.mis.dto.LotteryWinnerDTO;
import com.aube.mis.dto.PaginationResultDTO;
import com.aube.mis.dto.RelatedCallbackDTO;
import com.aube.mis.dto.ShowModelDTO;
import com.aube.mis.service.DanmuService;
import com.aube.mis.service.LotteryService;
import com.aube.mis.service.ShowSettingService;
import com.aube.mis.util.JsonUtil;
import com.aube.mis.vo.DataTableCriterias;

@Controller
@RequestMapping(value = "/danmu")
public class DanmuController extends AbstractController {

	private static Logger log = LoggerFactory.getLogger(DanmuController.class);

	@Resource
	DanmuService danmuService;

	@RequestMapping(value = "/list")
	public String list(HttpServletResponse response, ModelMap map, String videoId) {
		map.put("videoId", videoId);
		return "/danmu/list";
	}

	@RequestMapping(value = "/list/data.ajax", produces = "text/plain;charset=UTF-8")
	@ResponseBody
	public String listData(@ModelAttribute DataTableCriterias criterias, String videoId, Long startTime, Long endTime) {
		PaginationResultDTO<DanmuDTO> list = danmuService.getDanmuList(criterias, getShowId(), videoId, startTime, endTime);
		Map<String, Object> dataMap = new HashMap<String, Object>();
		dataMap.put("list", list.getResultList());
		dataMap.put("total", list.getTotal());
		return this.createSuccessResponse(dataMap);
	}
}
